# -- coding:utf-8 --
import datetime
import random
import pymysql
from dbutils.pooled_db import PooledDB


def create_24h_dy_data_for_calc(ip, p_date, v_list, time, v_220_all_ty=False, v_220_12_34_ty=False):
    """
    填充一天的采集数据
       2V2场景：
    01-----2vs2正常数据
    02-----2vs2高压同源、低压正常
    03-----2vs2低压同源、高压正常
    04-----2vs2高压同源、低压停电
    05-----2vs2高压停电、低压分列
    :param p_date:
    :param v_list:
    :param time:
    :param v_220_all_ty:
    :return:
    """
    POOL = PooledDB(creator=pymysql, maxconnections=6, mincached=2, maxcached=5, maxshared=3, blocking=True,
                    maxusage=None, setsession=[], ping=0, host=ip, port=3306, user='oetsky', password='Oetsky@123',
                    database="cvt_client_prod", charset='utf8')
    start_date_time = datetime.datetime.strptime(p_date, "%Y-%m-%d %H:%M:%S")
    end_data_time = start_date_time + datetime.timedelta(days=time)
    insert_sql = 'insert into da_voltage_data_temp(board_num,board_channel,channel_num,collect_time,time_type,' \
                 'aa_fundamental_frequency,aa_fundamental_amplitude,a3_harmonic_amplitude,a5_harmonic_amplitude,' \
                 'aa_fundamental_phase,a3_harmonic_phase,a5_harmonic_phase,' \
                 'bb_fundamental_frequency,bb_fundamental_amplitude,b3_harmonic_amplitude,b5_harmonic_amplitude,' \
                 'bb_fundamental_phase,b3_harmonic_phase,b5_harmonic_phase,' \
                 'cc_fundamental_frequency,cc_fundamental_amplitude,c3_harmonic_amplitude,c5_harmonic_amplitude,' \
                 'cc_fundamental_phase,c3_harmonic_phase,c5_harmonic_phase,' \
                 'zero_sequence_voltage_imbalance,negative_sequence_voltage_imbalance,' \
                 '`status`,channel_level,create_time,is_supplement)' \
                 'value(%s,%s,%s,STR_TO_DATE(%s,"%%Y-%%m-%%d %%H:%%i:%%s"),10,' \
                 '%s,%s,%s,%s,%s,%s,%s,' \
                 '%s,%s,%s,%s,%s,%s,%s,' \
                 '%s,%s,%s,%s,%s,%s,%s,' \
                 '0,0,1,%s,STR_TO_DATE(%s,"%%Y-%%m-%%d %%H:%%i:%%s"),1)'

    conn = POOL.connection()
    cursor = conn.cursor()
    try:
        cursor.execute("TRUNCATE da_voltage_data_temp;")
        print("已清空da_voltage_data_temp")

        while True:
            param_time_str = start_date_time.strftime("%Y-%m-%d %H:%M:%S")
            param_list = get_param_list(param_time_str, v_list, v_220_all_ty=v_220_all_ty,
                                        v_220_12_34_ty=v_220_12_34_ty)
            cursor.executemany(insert_sql, param_list)
            conn.commit()
            nid = cursor.lastrowid
            start_date_time = start_date_time + datetime.timedelta(minutes=1)
            # print(f'电压数据采集表自增ID========{nid}')
            if start_date_time >= end_data_time:
                break
    except Exception as e:
        print(e)
    finally:
        cursor.close()
        conn.close()


def get_param_list(param_time_str, v_list, amp_section=(60, 61), board_num=1, v_220_all_ty=False, v_220_12_34_ty=False):
    """
    获取数据
    :param param_time_str: 日期时间
    :param v_list: 存放电压等级、电压线路数、同源标志、分列标志、停电标志

    """
    data_list = []
    # 板卡通道&线路通道
    board_channel_num = 1

    v_330_level_temp = v_list[0]
    v_330_count_temp = v_list[1]
    v_330_ty_temp = v_list[2]
    v_330_fl_temp = v_list[3]
    v_330_td_temp = v_list[4]

    if v_330_count_temp > 0:
        h_amp_list = []  # a、b、c基波幅值
        h_ph_list = []  # a、b、c基波相位
        while True:
            # 基波幅值
            amp_a = round(random.uniform(amp_section[0], amp_section[1]), 5)
            amp_b = round(amp_a * random.uniform(0.999, 1.001), 5)
            amp_c = round(amp_a * random.uniform(0.999, 1.001), 5)
            # 基波相位
            ph_a = round(random.uniform(-1, 1), 2)
            ph_b = round(ph_a - random.uniform(7199, 7201), 2)
            ph_c = round(ph_a + random.uniform(7199, 7201), 2)
            h_amp_list.append((amp_a, amp_b, amp_c))
            h_ph_list.append((ph_a, ph_b, ph_c))
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                     50, amp_a, 0, 0, ph_a, 0, 0,
                     50, amp_b, 0, 0, ph_b, 0, 0,
                     50, amp_c, 0, 0, ph_c, 0, 0,
                     v_330_level_temp, param_time_str)
            data_list.append(param)

            board_channel_num += 1
            if board_channel_num > v_330_count_temp:
                break
        if v_330_ty_temp:
            # 33kV同源
            data_list.pop()  # 退一个通道的数据
            # data_list.pop()
            # data_list.pop()
            amp_a = round(h_amp_list[0][0] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_b = round(h_amp_list[0][1] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_c = round(h_amp_list[0][2] * (1 + random.uniform(0.00001, 0.00003)), 5)
            # h_amp_list[-1] = (amp_a, amp_b, amp_c)
            ph_a = round(h_ph_list[0][0] + random.uniform(-0.01, 0.01), 2)
            ph_b = round(h_ph_list[0][1] + random.uniform(-0.01, 0.01), 2)
            ph_c = round(h_ph_list[0][2] + random.uniform(-0.01, 0.01), 2)
            # h_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            ty_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, amp_a, 0, 0, ph_a, 0, 0,
                        50, amp_b, 0, 0, ph_b, 0, 0,
                        50, amp_c, 0, 0, ph_c, 0, 0,
                        v_330_level_temp, param_time_str)
            data_list.append(ty_param)
            # ty_param = (board_num_temp, board_channel_num - 2, board_channel_num - 2, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_330_level_temp, param_time_str)
            # data_list.append(ty_param)
            # ty_param = (board_num_temp, board_channel_num - 3, board_channel_num - 3, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_330_level_temp, param_time_str)
            # data_list.append(ty_param)
        if v_330_fl_temp:
            # 高压侧分列
            ph_a = round(h_ph_list[0][0] + random.uniform(12, 13), 2)
            ph_b = round(h_ph_list[0][1] + random.uniform(12, 13), 2)
            ph_c = round(h_ph_list[0][2] + random.uniform(12, 13), 2)
            h_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            fl_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, h_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                        50, h_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                        50, h_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                        v_330_level_temp, param_time_str)
            data_list.pop()
            data_list.append(fl_param)
        if v_330_td_temp:
            # 高压停电
            board_channel_num -= 2
            data_list.pop()
            data_list.pop()
            while True:
                amp_a = round(round(random.uniform(0, 54)), 5)
                amp_b = round(amp_a * (1 + random.uniform(0.00001, 0.00003)), 5)
                amp_c = round(amp_b * (1 + random.uniform(0.00001, 0.00003)), 5)
                ph_a = round(h_ph_list[0][0] + random.uniform(-0.03, 0.03), 2)
                ph_b = round(h_ph_list[0][1] + random.uniform(-0.03, 0.03), 2)
                ph_c = round(h_ph_list[0][2] + random.uniform(-0.03, 0.03), 2)
                h_amp_list.append((amp_a, amp_b, amp_c))
                h_ph_list.append((ph_a, ph_b, ph_c))
                if board_channel_num <= 5:
                    board_num_temp = board_num
                elif board_channel_num <= 10:
                    board_num_temp = board_num + 1
                fl_param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                            50, h_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                            50, h_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                            50, h_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                            v_330_level_temp, param_time_str)
                data_list.append(fl_param)
                board_channel_num += 1
                if board_channel_num > v_330_count_temp:
                    break

    v_220_level_temp = v_list[5]
    v_220_count_temp = v_list[6]
    v_220_ty_temp = v_list[7]
    v_220_fl_temp = v_list[8]
    v_220_td_temp = v_list[9]

    if v_220_count_temp > 0:
        l_amp_list = []
        l_ph_list = []
        while True:
            # 低压侧参数填充
            # 基波幅值
            amp_a = round(random.uniform(amp_section[0], amp_section[1]), 5)
            amp_b = round(amp_a * random.uniform(0.999, 1.001), 5)
            amp_c = round(amp_a * random.uniform(0.999, 1.001), 5)
            # 基波相位
            ph_a = round(random.uniform(-1, 1), 2)
            ph_b = round(ph_a - random.uniform(7199, 7201), 2)
            ph_c = round(ph_a + random.uniform(7199, 7201), 2)
            l_amp_list.append((amp_a, amp_b, amp_c))
            l_ph_list.append((ph_a, ph_b, ph_c))
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                     50, amp_a, 0, 0, ph_a, 0, 0,
                     50, amp_b, 0, 0, ph_b, 0, 0,
                     50, amp_c, 0, 0, ph_c, 0, 0,
                     v_220_level_temp, param_time_str)
            data_list.append(param)
            board_channel_num += 1
            if board_channel_num > v_220_count_temp + v_330_count_temp:
                break
        if v_220_ty_temp:
            # 低压侧同源
            data_list.pop()
            # data_list.pop()
            # data_list.pop()
            # data_list.pop()
            # data_list.pop()
            amp_a = round(l_amp_list[0][0] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_b = round(l_amp_list[0][1] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_c = round(l_amp_list[0][2] * (1 + random.uniform(0.00001, 0.00003)), 5)
            # l_amp_list[-1] = (amp_a, amp_b, amp_c)
            ph_a = round(l_ph_list[0][0] + random.uniform(-0.01, 0.01), 2)
            ph_b = round(l_ph_list[0][1] + random.uniform(-0.01, 0.01), 2)
            ph_c = round(l_ph_list[0][2] + random.uniform(-0.01, 0.01), 2)
            # l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            ty_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, amp_a, 0, 0, ph_a, 0, 0,
                        50, amp_b, 0, 0, ph_b, 0, 0,
                        50, amp_c, 0, 0, ph_c, 0, 0,
                        v_220_level_temp, param_time_str)
            data_list.append(ty_param)
            #
            # ty_param = (board_num_temp, board_channel_num - 2, board_channel_num - 2, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_220_level_temp, param_time_str)
            # data_list.append(ty_param)
            # ty_param = (board_num_temp, board_channel_num - 3, board_channel_num - 3, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_220_level_temp, param_time_str)
            # data_list.append(ty_param)
            # ty_param = (board_num_temp, board_channel_num - 4, board_channel_num - 4, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_220_level_temp, param_time_str)
            # data_list.append(ty_param)
            # ty_param = (board_num_temp, board_channel_num - 5, board_channel_num - 5, param_time_str,
            #             50, amp_a, 0, 0, ph_a, 0, 0,
            #             50, amp_b, 0, 0, ph_b, 0, 0,
            #             50, amp_c, 0, 0, ph_c, 0, 0,
            #             v_220_level_temp, param_time_str)
            # data_list.append(ty_param)
        if v_220_all_ty:
            for i in range(v_220_count_temp - 1):
                amp_a = l_amp_list[0][0]
                amp_b = l_amp_list[0][1]
                amp_c = l_amp_list[0][2]

                ph_a = l_ph_list[0][0]
                ph_b = l_ph_list[0][1]
                ph_c = l_ph_list[0][2]

                if board_channel_num <= 5:
                    board_num_temp = board_num
                elif board_channel_num <= 10:
                    board_num_temp = board_num + 1
                ty_param = (board_num_temp, i + 2, i + 2, param_time_str,
                            50, amp_a, 0, 0, ph_a, 0, 0,
                            50, amp_b, 0, 0, ph_b, 0, 0,
                            50, amp_c, 0, 0, ph_c, 0, 0,
                            v_220_level_temp, param_time_str)
                data_list[i + 1] = ty_param

        if v_220_12_34_ty:
            ty_param_2 = (board_num_temp, 2, 2, param_time_str,
                          50, l_amp_list[0][0], 0, 0, l_ph_list[0][0], 0, 0,
                          50, l_amp_list[0][1], 0, 0, l_ph_list[0][1], 0, 0,
                          50, l_amp_list[0][2], 0, 0, l_ph_list[0][2], 0, 0,
                          v_220_level_temp, param_time_str)
            ty_param_4 = (board_num_temp, 4, 4, param_time_str,
                          50, l_amp_list[2][0], 0, 0, l_ph_list[2][0], 0, 0,
                          50, l_amp_list[2][1], 0, 0, l_ph_list[2][1], 0, 0,
                          50, l_amp_list[2][2], 0, 0, l_ph_list[2][2], 0, 0,
                          v_220_level_temp, param_time_str)

            data_list[1] = ty_param_2
            data_list[3] = ty_param_4

        if v_220_fl_temp:
            # 低压侧分列
            ph_a = round(l_ph_list[-2][0] + random.uniform(12, 13), 2)
            ph_b = round(l_ph_list[-2][1] + random.uniform(12, 13), 2)
            ph_c = round(l_ph_list[-2][2] + random.uniform(12, 13), 2)
            l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            fl_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                        50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                        50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                        v_220_level_temp, param_time_str)
            data_list.pop()
            data_list.append(fl_param)
        if v_220_td_temp:
            # 低压停电
            board_channel_num -= 1
            data_list.pop()
            # data_list.pop()
            # data_list.pop()
            # data_list.pop()
            # data_list.pop()
            # data_list.pop()
            while True:
                amp_a = round(round(random.uniform(0, 10)), 5)
                amp_b = round(amp_a * (1 + random.uniform(0.00001, 0.00003)), 5)
                amp_c = round(amp_b * (1 + random.uniform(0.00001, 0.00003)), 5)
                ph_a = round(l_ph_list[0][0] + random.uniform(-0.03, 0.03), 2)
                ph_b = round(l_ph_list[0][1] + random.uniform(-0.03, 0.03), 2)
                ph_c = round(l_ph_list[0][2] + random.uniform(-0.03, 0.03), 2)
                l_amp_list.append((amp_a, amp_b, amp_c))
                l_ph_list.append((ph_a, ph_b, ph_c))
                if board_channel_num <= 5:
                    board_num_temp = board_num
                elif board_channel_num <= 10:
                    board_num_temp = board_num + 1
                fl_param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                            50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                            50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                            50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                            v_220_level_temp, param_time_str)
                data_list.append(fl_param)
                board_channel_num += 1
                if board_channel_num > v_220_count_temp + v_330_count_temp:
                    break

    v_110_level_temp = v_list[10]
    v_110_count_temp = v_list[11]
    v_110_ty_temp = v_list[12]
    v_110_fl_temp = v_list[13]
    v_110_td_temp = v_list[14]

    if v_110_count_temp > 0:
        l_amp_list = []
        l_ph_list = []
        while True:
            # 低压侧参数填充
            # 基波幅值
            amp_a = round(random.uniform(amp_section[0], amp_section[1]), 5)
            amp_b = round(amp_a * random.uniform(0.999, 1.001), 5)
            amp_c = round(amp_a * random.uniform(0.999, 1.001), 5)
            # 基波相位
            ph_a = round(random.uniform(100, 102), 2)
            ph_b = round(ph_a - random.uniform(7199, 7201), 2)
            ph_c = round(ph_a + random.uniform(7199, 7201), 2)
            l_amp_list.append((amp_a, amp_b, amp_c))
            l_ph_list.append((ph_a, ph_b, ph_c))
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                     50, amp_a, 0, 0, ph_a, 0, 0,
                     50, amp_b, 0, 0, ph_b, 0, 0,
                     50, amp_c, 0, 0, ph_c, 0, 0,
                     v_110_level_temp, param_time_str)
            data_list.append(param)
            board_channel_num += 1
            if board_channel_num > v_110_count_temp + v_220_count_temp + v_330_count_temp:
                break
        if v_110_ty_temp:
            # 低压侧同源
            data_list.pop()
            amp_a = round(l_amp_list[0][0] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_b = round(l_amp_list[0][1] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_c = round(l_amp_list[0][2] * (1 + random.uniform(0.00001, 0.00003)), 5)
            l_amp_list[-1] = (amp_a, amp_b, amp_c)
            ph_a = round(l_ph_list[0][0] + random.uniform(-0.01, 0.01), 2)
            ph_b = round(l_ph_list[0][1] + random.uniform(-0.01, 0.01), 2)
            ph_c = round(l_ph_list[0][2] + random.uniform(-0.01, 0.01), 2)
            l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            ty_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, amp_a, 0, 0, ph_a, 0, 0,
                        50, amp_b, 0, 0, ph_b, 0, 0,
                        50, amp_c, 0, 0, ph_c, 0, 0,
                        v_110_level_temp, param_time_str)
            data_list.append(ty_param)
        if v_110_fl_temp:
            # 低压侧分列
            ph_a = round(l_ph_list[0][0] + random.uniform(13, 14), 2)
            ph_b = round(l_ph_list[0][1] + random.uniform(13, 14), 2)
            ph_c = round(l_ph_list[0][2] + random.uniform(13, 14), 2)
            # ph_x = round(l_ph_list[0][0] + random.uniform(26, 27), 2)
            # ph_y = round(l_ph_list[0][1] + random.uniform(26, 27), 2)
            # ph_z = round(l_ph_list[0][2] + random.uniform(26, 27), 2)
            l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            fl_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                        50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                        50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                        v_110_level_temp, param_time_str)
            # fl_param1 = (board_num_temp, board_channel_num - 2, board_channel_num - 2, param_time_str,
            #             50, l_amp_list[-1][0], 0, 0, ph_x, 0, 0,
            #             50, l_amp_list[-1][1], 0, 0, ph_y, 0, 0,
            #             50, l_amp_list[-1][2], 0, 0, ph_z, 0, 0,
            #             v_110_level_temp, param_time_str)
            # data_list.pop()
            data_list.pop()
            # data_list.append(fl_param1)
            data_list.append(fl_param)
        if v_110_td_temp:
            # 低压停电
            board_channel_num -= 2
            data_list.pop()
            data_list.pop()
            while True:
                amp_a = round(round(random.uniform(0, 10)), 5)
                amp_b = round(amp_a * (1 + random.uniform(0.00001, 0.00003)), 5)
                amp_c = round(amp_b * (1 + random.uniform(0.00001, 0.00003)), 5)
                ph_a = round(l_ph_list[0][0] + random.uniform(-0.03, 0.03), 2)
                ph_b = round(l_ph_list[0][1] + random.uniform(-0.03, 0.03), 2)
                ph_c = round(l_ph_list[0][2] + random.uniform(-0.03, 0.03), 2)
                l_amp_list.append((amp_a, amp_b, amp_c))
                l_ph_list.append((ph_a, ph_b, ph_c))
                if board_channel_num <= 5:
                    board_num_temp = board_num
                elif board_channel_num <= 10:
                    board_num_temp = board_num + 1
                fl_param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                            50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                            50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                            50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                            v_110_level_temp, param_time_str)
                data_list.append(fl_param)
                board_channel_num += 1
                if board_channel_num > v_110_count_temp + v_220_count_temp + v_330_count_temp:
                    break

    v_10_level_temp = v_list[15]
    v_10_count_temp = v_list[16]
    v_10_ty_temp = v_list[17]
    v_10_fl_temp = v_list[18]
    v_10_td_temp = v_list[19]

    if v_10_count_temp > 0:
        l_amp_list = []
        l_ph_list = []
        while True:
            # 低压侧参数填充
            # 基波幅值
            amp_a = round(random.uniform(amp_section[0], amp_section[1]), 5)
            amp_b = round(amp_a * random.uniform(0.999, 1.001), 5)
            amp_c = round(amp_a * random.uniform(0.999, 1.001), 5)
            # 基波相位
            ph_a = round(random.uniform(-1, 1), 2)
            ph_b = round(ph_a - random.uniform(7199, 7201), 2)
            ph_c = round(ph_a + random.uniform(7199, 7201), 2)
            l_amp_list.append((amp_a, amp_b, amp_c))
            l_ph_list.append((ph_a, ph_b, ph_c))
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                     50, amp_a, 0, 0, ph_a, 0, 0,
                     50, amp_b, 0, 0, ph_b, 0, 0,
                     50, amp_c, 0, 0, ph_c, 0, 0,
                     v_10_level_temp, param_time_str)
            data_list.append(param)
            board_channel_num += 1
            if board_channel_num > v_10_count_temp + v_110_count_temp + v_220_count_temp + v_330_count_temp:
                break
        if v_10_ty_temp:
            # 低压侧同源
            data_list.pop()
            amp_a = round(l_amp_list[0][0] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_b = round(l_amp_list[0][1] * (1 + random.uniform(0.00001, 0.00003)), 5)
            amp_c = round(l_amp_list[0][2] * (1 + random.uniform(0.00001, 0.00003)), 5)
            l_amp_list[-1] = (amp_a, amp_b, amp_c)
            ph_a = round(l_ph_list[0][0] + random.uniform(-0.01, 0.01), 2)
            ph_b = round(l_ph_list[0][1] + random.uniform(-0.01, 0.01), 2)
            ph_c = round(l_ph_list[0][2] + random.uniform(-0.01, 0.01), 2)
            l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            ty_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, amp_a, 0, 0, ph_a, 0, 0,
                        50, amp_b, 0, 0, ph_b, 0, 0,
                        50, amp_c, 0, 0, ph_c, 0, 0,
                        v_10_level_temp, param_time_str)
            data_list.append(ty_param)
        if v_10_fl_temp:
            # 低压侧分列
            ph_a = round(l_ph_list[0][0] + random.uniform(12, 13), 2)
            ph_b = round(l_ph_list[0][1] + random.uniform(12, 13), 2)
            ph_c = round(l_ph_list[0][2] + random.uniform(12, 13), 2)
            l_ph_list[-1] = (ph_a, ph_b, ph_c)
            if board_channel_num <= 5:
                board_num_temp = board_num
            elif board_channel_num <= 10:
                board_num_temp = board_num + 1
            fl_param = (board_num_temp, board_channel_num - 1, board_channel_num - 1, param_time_str,
                        50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                        50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                        50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                        v_10_level_temp, param_time_str)
            data_list.pop()
            data_list.append(fl_param)
        if v_10_td_temp:
            # 低压停电
            board_channel_num -= 2
            data_list.pop()
            data_list.pop()
            while True:
                amp_a = round(round(random.uniform(0, 54)), 5)
                amp_b = round(amp_a * (1 + random.uniform(0.00001, 0.00003)), 5)
                amp_c = round(amp_b * (1 + random.uniform(0.00001, 0.00003)), 5)
                ph_a = round(l_ph_list[0][0] + random.uniform(-0.03, 0.03), 2)
                ph_b = round(l_ph_list[0][1] + random.uniform(-0.03, 0.03), 2)
                ph_c = round(l_ph_list[0][2] + random.uniform(-0.03, 0.03), 2)
                l_amp_list.append((amp_a, amp_b, amp_c))
                l_ph_list.append((ph_a, ph_b, ph_c))
                if board_channel_num <= 5:
                    board_num_temp = board_num
                elif board_channel_num <= 10:
                    board_num_temp = board_num + 1
                fl_param = (board_num_temp, board_channel_num, board_channel_num, param_time_str,
                            50, l_amp_list[-1][0], 0, 0, ph_a, 0, 0,
                            50, l_amp_list[-1][1], 0, 0, ph_b, 0, 0,
                            50, l_amp_list[-1][2], 0, 0, ph_c, 0, 0,
                            v_10_level_temp, param_time_str)
                data_list.append(fl_param)
                board_channel_num += 1
                if board_channel_num > v_10_count_temp + v_110_count_temp + v_220_count_temp + v_330_count_temp:
                    break
    return data_list


if __name__ == '__main__':
    ip = '192.168.253.113'
    # ip = argv[1]
    # time = argv[2]
    time = 2
    now_date = datetime.date.today()
    pre_date = now_date + datetime.timedelta(days=-1)
    # print(pre_date)
    pre_date = pre_date.strftime("%Y-%m-%d %H:%M:%S")
    v_330_level = 8  # 330kV电压等级对应的字典键值
    v_330_count = 0  # 330kV电压等级线路数
    v_330_ty = False  # 330kV电压等级同源标志  True  False
    v_330_fl = False  # 330kV电压等级分列标志
    v_330_td = False  # 330kV电压等级停电标志

    v_220_level = 5  # 220kV电压等级对应的字典键值
    v_220_count = 2  # 220kV电压等级线路数
    v_220_ty = False  # 220kV电压等级同源标志  True  False
    v_220_fl = False  # 220kV电压等级分列标志
    v_220_td = False  # 220kV电压等级停电标志

    v_110_level = 4  # 110kV电压等级对应的字典键值
    v_110_count = 2  # 110kV电压等级线路数
    v_110_ty = False  # 110kV电压等级同源标志  True  False
    v_110_fl = False  # 110kV电压等级分列标志
    v_110_td = False  # 110kV电压等级停电标志

    v_10_level = 3  # 10kV电压等级对应的字典键值
    v_10_count = 0  # 10kV电压等级线路数
    v_10_ty = False  # 10kV电压等级同源标志  True  False
    v_10_fl = False  # 10kV电压等级分列标志
    v_10_td = False  # 10kV电压等级停电标志

    v_arg_list = [v_330_level, v_330_count, v_330_ty, v_330_fl, v_330_td, v_220_level, v_220_count, v_220_ty, v_220_fl,
                  v_220_td, v_110_level, v_110_count, v_110_ty, v_110_fl, v_110_td, v_10_level, v_10_count, v_10_ty,
                  v_10_fl, v_10_td]
    create_24h_dy_data_for_calc(ip, p_date=pre_date, v_list=v_arg_list, time=time)
